-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable threading in libcxx in all cases #498
base: main
Are you sure you want to change the base?
Conversation
I kicked off the CI builds and it looks like they're failing with:
I think the failure is due to the fact that |
Could you do some measurements of the code size impact of this change? For a basic C++ program that doesn't use threads, how much code size difference is there between threading disabled in the libcxx build vs. threading stubbed out in libc? |
As far as I understand it, |
I just compared the size difference between a C++ the version with stubs and threading in libc++ is actually smaller (223K --> 183K) this is not at all a fair comparison, but the real different is probably minor? |
Would it not work? A .so can reference symbols from the main binary on ELF platforms, so provided it references an undefined |
Hmm, you are indeed correct. I forgot that you can do that. I'm still not sure how to handle documentation and user expectations for these issues though (especially since linkage seems to often be poorly understood). |
I think we can say that you have to link the main app with |
@alexcrichton stated above that requiring users to explicitly pass However, I was just reminded of how glibc a long time ago would require passing |
We could also change the clang compiler driver to do so. |
Oh definitely don't take my off-hand thought as a given or anything like that. We're already surprising lots of folks by not having pthread apis at all, and in general folks expect pthread apis to be available and do something. I don't think it would be great if (regardless though this won't be able to land unless CI is passing, so something would need to be done about that) |
I think the idea with these |
To be honest I don't actually understand the problem here. @alexcrichton says that the library should not be explicitly opted into while @sbc100 says it should be (which is also how I understood this should work). What is the UX design goal here? I'm lost. |
Sorry I can try to explain more. Right now This means that users of libcxx who did not opt-in with That's at least my understanding of the situation, but I'm no C++ expert, so I could very well be off-the-mark here. |
So if I understand it right, there's a Can we make that |
That's my understanding, yeah. Libcxx either does or doesn't use pthreads and that's a build-time-of-libcxx decision, not a build-time-when-you-pull-in-libcxx decision. Whether or not what you're proposing is viable, having a build-time-when-you-pull-in-libcxx |
To put forth an idea which I do know will work, but I realize may be controversial: merge "emulated pthreads" directly into wasi-libc. Don't require |
Sure, but that argument could also be made for all the emulated stuff. The simplest solution in all cases is just to include emulation for everything and then more things "just work". However, that would go again the current design of wasi-libc which is not to include things that are fake/emulated unless they are opt-ed into explicitly. Another possible downside: If we enable threading in libc++ will that cause it be slower/bigger/bloated compared to the no-threads version? I.e. will be be redundantly locking mutexed etc when it doesn't need to? I guess LTO should take care of more of that by not all. |
Okay, let me try to approach this from the other end.
|
Sure. Multi-threaded runtimes are not really a thing since wasi-threads is hold for now (pending shared-everything threads). So single-threaded runtimes are the primary target of wasi-libc and wasi-sdk. The question is, how much software can be built for a target that doesn't support threads? For example, I don't know if LLVM can be built without threading support since I don't know of any other platforms it targets that don'e have thread. So, it may need the emulation in order to build at all. But its seems reasonable in that case for anyone building such software to opt into the fake/emulated threading support doesn't it? |
LLVM can be built without threading support (it has an (I should note that I have a working port of LLVM to WASI and the PRs mentioned above directly relate to it.) Most software that uses threads as a way to optionally improve the performance of some operation through parallelism, in my experience, has a way to bypass the spawning of additional threads. As another example of something I ported to WASI, nextpnr also hit this problem. In this case, I had organizational influence that helped me add the required
From my perspective, the desired end result is that the opt-in is done at the build system level ( Does this help clear things up a bit? |
Surely adding link flags such as |
Completely reasonable, albeit since the C++ compiler frontend will add |
This has not been tested locally! I don't have enough disk space to store yet another LLVM tree, and I couldn't quite figure out how to test only the sysroot changes, so I'm hoping the CI pipeline can test this
This enables threads in libcxx for all builds, building on top of the stubs for libpthread